<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>用户产品运费模板管理</title>
    <meta name="decorator" content="default"/>
    <script type="text/javascript">
        $(document).ready(function () {
            //$("#name").focus();
            $("#inputForm").validate({
                submitHandler: function (form) {
                    loading('正在提交，请稍等...');
                    form.submit();
                },
                errorContainer: "#messageBox",
                errorPlacement: function (error, element) {
                    $("#messageBox").text("输入有误，请先更正。");
                    if (element.is(":checkbox") || element.is(":radio") || element.parent().is(".input-append")) {
                        error.appendTo(element.parent().parent());
                    } else {
                        error.insertAfter(element);
                    }
                }
            });
        });

        function addRow(list, idx, tpl, row) {
            $(list).append(Mustache.render(tpl, {
                idx: idx, delBtn: true, row: row
            }));
            $(list + idx).find("select").each(function () {
                $(this).val($(this).attr("data-value"));
            });
            $(list + idx).find("input[type='checkbox'], input[type='radio']").each(function () {
                var ss = $(this).attr("data-value").split(',');
                for (var i = 0; i < ss.length; i++) {
                    if ($(this).val() == ss[i]) {
                        $(this).attr("checked", "checked");
                    }
                }
            });
        }

        function delRow(obj, prefix) {
            var id = $(prefix + "_id");
            var delFlag = $(prefix + "_delFlag");
            delFlag = "1";
            if (id.val() == "") {
                $(obj).parent().parent().remove();
            } else if (delFlag.val() == "0") {
                delFlag.val("1");
                $(obj).html("&divide;").attr("title", "撤销删除");
                $(obj).parent().parent().addClass("error");
            } else if (delFlag.val() == "1") {
                delFlag.val("0");
                $(obj).html("&times;").attr("title", "删除");
                $(obj).parent().parent().removeClass("error");
            }
        }
    </script>
</head>
<body>
<ul class="nav nav-tabs">
    <li><a href="${ctx}/sys/user/hkUserProductFreight/">用户产品运费模板列表</a></li>
    <li class="active"><a
            href="${ctx}/sys/user/hkUserProductFreight/form?id=${hkUserProductFreight.id}">用户产品运费模板<shiro:hasPermission
            name="sys:user:hkUserProductFreight:edit">${not empty hkUserProductFreight.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission
            name="sys:user:hkUserProductFreight:edit">查看</shiro:lacksPermission></a></li>
</ul>
<br/>
<form:form id="inputForm" modelAttribute="hkUserProductFreight" action="${ctx}/sys/user/hkUserProductFreight/save"
           method="post" class="form-horizontal">
    <form:hidden path="id"/>
    <sys:message content="${message}"/>
    <%--<div class="control-group">
        <label class="control-label">用户：</label>
        <div class="controls">
        </div>
    </div>--%>
    <%--<div class="control-group">
        <label class="control-label">是否系统模板：</label>
        <div class="controls">
            <form:select path="issystem" class="input-xlarge ">
                <form:option value="" label=""/>
                <form:options items="${fns:getDictList('yes_no')}" itemLabel="label" itemValue="value"
                              htmlEscape="false" cssClass=""/>
            </form:select>
        </div>
    </div>--%>
    <div class="control-group">
        <label class="control-label">模板名称：</label>
        <div class="controls">
            <form:input path="name" htmlEscape="false" maxlength="100" class="input-xlarge required"/>
            <span class="help-inline"><font color="red">*</font> </span>
        </div>
    </div>
    <%--<div class="control-group">
        <label class="control-label">是否除之外：</label>
        <div class="controls">
            <form:select path="isexcept" class="input-xlarge ">
                <form:option value="" label=""/>
                <form:options items="${fns:getDictList('yes_no')}" itemLabel="label" itemValue="value"
                              htmlEscape="false" cssClass="cke_required"/>
            </form:select>
        </div>
    </div>--%>
    <div class="control-group">
        <label class="control-label">适用省份：</label>
        <div class="controls">
            <sys:treeselect id="provinceId" name="provinceId" value="${hkUserProductFreight.provinceId}" labelName=""
                            labelValue="${hkUserProductFreight.provinceName}"
                            title="区域" url="/media/hkMediaUserShopRegion/chinaProviceData" cssClass="required"
                            cssStyle="" dataMsgRequired="必选"
                            allowClear="false"
                            notAllowSelectParent="true" checked="true"/>
            <span class="help-inline"><font color="red">*</font> </span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">基础运费包含件数：</label>
        <div class="controls">
            <form:input path="piece" htmlEscape="false" maxlength="11" class="input-xlarge digits required"/>(件)
            <span class="help-inline"><font color="red">*</font> </span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">基础运费：</label>
        <div class="controls">
            <form:input path="money" htmlEscape="false" maxlength="11" class="input-xlarge number required"/>(元)
            <span class="help-inline"><font color="red">*</font> </span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">增加件：</label>
        <div class="controls">
            <form:input path="addPiece" htmlEscape="false" maxlength="11" class="input-xlarge digits required"/>(件)
            <span class="help-inline"><font color="red">*</font> </span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">增加金额：</label>
        <div class="controls">
            <form:input path="addMoney" htmlEscape="false" maxlength="11" class="input-xlarge number required"/>(元)
            <span class="help-inline"><font color="red">*</font> </span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">备注：</label>
        <div class="controls">
            <form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="100" class="input-xxlarge "/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">不适用省份邮费：</label>
        <div class="controls">
            <table id="contentTable" class="table table-striped table-bordered table-condensed">
                <thead>
                <tr>
                    <th class="hide"></th>
                        <%-- <th>用户</th>--%>
                    <th>基础运费包含件数</th>
                    <th>基础运费</th>
                    <th>增加件</th>
                    <th>增加金额</th>
                    <th>适用省份</th>
                    <th>备注</th>
                    <shiro:hasPermission name="sys:user:hkUserProductFreight:edit">
                        <th width="10">操作</th>
                    </shiro:hasPermission>
                </tr>
                </thead>
                <tbody id="hkUserProductAreaFreightList">
                </tbody>
                <shiro:hasPermission name="sys:user:hkUserProductFreight:edit">
                    <tfoot>
                    <tr>
                        <td colspan="9"><a href="javascript:"
                                           onclick="addRow('#hkUserProductAreaFreightList', hkUserProductAreaFreightRowIdx, hkUserProductAreaFreightTpl);hkUserProductAreaFreightRowIdx = hkUserProductAreaFreightRowIdx + 1;"
                                           class="btn">新增</a></td>
                    </tr>
                    </tfoot>
                </shiro:hasPermission>
            </table>
            <script type="text/template" id="hkUserProductAreaFreightTpl">//<!--
						<tr id="hkUserProductAreaFreightList{{idx}}">
							<td class="hide">
								<input id="hkUserProductAreaFreightList{{idx}}_id" name="hkUserProductAreaFreightList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
								<input id="hkUserProductAreaFreightList{{idx}}_delFlag" name="hkUserProductAreaFreightList[{{idx}}].delFlag" type="hidden" value="0"/>
							</td>
							<td>
								<input id="hkUserProductAreaFreightList{{idx}}_piece" name="hkUserProductAreaFreightList[{{idx}}].piece" type="text" value="{{row.piece}}" maxlength="11" class="input-small  digits required"/>(件)
							    <span class="help-inline"><font color="red">*</font> </span>
							</td>
							<td>
								<input id="hkUserProductAreaFreightList{{idx}}_money" name="hkUserProductAreaFreightList[{{idx}}].money" type="text" value="{{row.money}}" maxlength="11" class="input-small number required"/>(元)
							    <span class="help-inline"><font color="red">*</font> </span>
							</td>
							<td>
								<input id="hkUserProductAreaFreightList{{idx}}_addPiece" name="hkUserProductAreaFreightList[{{idx}}].addPiece" type="text" value="{{row.addPiece}}" maxlength="11" class="input-small  digits required"/>(件)
							    <span class="help-inline"><font color="red">*</font> </span>
							</td>
							<td>
								<input id="hkUserProductAreaFreightList{{idx}}_addMoney" name="hkUserProductAreaFreightList[{{idx}}].addMoney" type="text" value="{{row.addMoney}}" maxlength="11" class="input-small number required"/>(元)
							    <span class="help-inline"><font color="red">*</font> </span>
							</td>
							<td>
								<sys:treeselect id="hkUserProductAreaFreightList{{idx}}_provinceId" name="hkUserProductAreaFreightList[{{idx}}].provinceId" value="{{row.provinceId}}" labelName="hkUserProductAreaFreightList{{idx}}.provinceName" labelValue="{{row.provinceName}}"
									title="区域" url="/media/hkMediaUserShopRegion/chinaProviceData" cssClass="required" cssStyle="" dataMsgRequired="必选" allowClear="false" notAllowSelectParent="true" checked="true" />
							    <span class="help-inline"><font color="red">*</font> </span>
							</td>
							<td>
								<textarea id="hkUserProductAreaFreightList{{idx}}_remarks" name="hkUserProductAreaFreightList[{{idx}}].remarks" rows="4" maxlength="100" class="input-small ">{{row.remarks}}</textarea>
							</td>
							<shiro:hasPermission name="sys:user:hkUserProductFreight:edit"><td class="text-center" width="10">
								{{#delBtn}}<span class="close" onclick="delRow(this, '#hkUserProductAreaFreightList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
							</td></shiro:hasPermission>
						</tr>//-->
            </script>
            <script type="text/javascript">
                var hkUserProductAreaFreightRowIdx = 0,
                    hkUserProductAreaFreightTpl = $("#hkUserProductAreaFreightTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g, "");
                $(document).ready(function () {
                    var data = ${fns:toJson(hkUserProductFreight.hkUserProductAreaFreightList)};
                    for (var i = 0; i < data.length; i++) {
                        addRow('#hkUserProductAreaFreightList', hkUserProductAreaFreightRowIdx, hkUserProductAreaFreightTpl, data[i]);
                        hkUserProductAreaFreightRowIdx = hkUserProductAreaFreightRowIdx + 1;
                    }
                });
            </script>
        </div>
    </div>
    <div class="form-actions">
        <shiro:hasPermission name="sys:user:hkUserProductFreight:edit"><input id="btnSubmit" class="btn btn-primary"
                                                                              type="submit"
                                                                              value="保 存"/>&nbsp;</shiro:hasPermission>
        <input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
    </div>
</form:form>
</body>
</html>